/** 该中间件不采用 log4js ，等研究明白 log4 升级一下 */

import { NestMiddleware } from '@nestjs/common';
import { NextFunction, Request, Response } from 'express';
import { inspect } from 'node:util';
import dayjs from 'dayjs';

export class LoggerMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    const message = `
    ********************************
    request method:${req.method}
    request query:${inspect(req.query)}
    request body:${inspect(req.body)}
    request url:${inspect(req.originalUrl)}
    request time:${dayjs().format('YYYY-MM-DD HH:mm:ss')}
    ********************************
    `;
    console.log(message);
    next();
  }
}
